package com.leji.song.httpInterface;

import android.content.Context;
import com.dgl.sdk.util.JsonUtil;
import com.leji.song.extra.BaseCoreActivity;

/**
 * Created by colin.ding on 2014/5/16.
 */
public class NomalResult{

    public static Object doResult(Object t, Context context){

        Result result =
                JsonUtil.fromJson((String) t, Result.class);

        if(result == null){
            ((BaseCoreActivity)context).showToast("未知错误！");
            return "";
        }

        if(result.Code.equals("2")){

            ((BaseCoreActivity)context).showToast(result.getError());


        }else if(result.Code.equals("0")){

            return result.getReturn();
        }

        return "";
    }

    public static Result getResult(Object t, Context context){

        Result result =
                JsonUtil.fromJson((String) t, Result.class);

        if(result == null){
            ((BaseCoreActivity)context).showToast("未知错误！");
            return null;
        }else{
            return result;
        }

    }

    public static Boolean isNormalResult(Object t, Context context){

        Result result =
                JsonUtil.fromJson((String) t, Result.class);

        if(result == null){
            ((BaseCoreActivity)context).showToast("未知错误！");
            return false;
        }

        if(result.Code.equals("2")){

            ((BaseCoreActivity)context).showToast(result.getError());
            return false;


        }else if(result.Code.equals("0")){

            return true;
        }

        return false;
    }


    public class Result{
        public  String Code;
        public  String Error;
        public  Object Return;


        public String getCode() {
            return Code;
        }

        public void setCode(String code) {
            Code = code;
        }

        public String getError() {
            return Error;
        }

        public void setError(String error) {
            Error = error;
        }

        public Object getReturn() {
            return Return;
        }

        public void setReturn(Object aReturn) {
            Return = aReturn;
        }
    }

}